package com.lingkang.flychat.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.lingkang.flychat.R;
import com.lingkang.flychat.entity.MessageList;

import java.util.List;

public class MessageListAdapter extends BaseAdapter {
    private Context context;
    private List<MessageList> lists;

    public MessageListAdapter(Context context, List<MessageList> lists) {
        super();
        this.context = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public MessageList getItem(int arg0) {
        return lists.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MessageList entity = lists.get(position);
        convertView = View.inflate(context, R.layout.item_msg, null);
        ImageView iv_img = convertView.findViewById(R.id.iv_img);
        TextView tv_title = convertView.findViewById(R.id.tv_title);
        TextView tv_description = convertView.findViewById(R.id.tv_description);
        tv_title.setText(entity.getTitle());
        tv_description.setText(entity.getDescription());
        Glide.with(context)
                .load(entity.getImg())
                .apply(RequestOptions.bitmapTransform(new CircleCrop())) //图片圆形
                .into(iv_img);
        return convertView;
    }


}
